<template>
	<view class="starnoteview" @click="naviToDetail">
		<!-- <view v-for="picture in pictures" :key="picture.id">
			<image :src="picture.pictureurl" mode="aspectFill" v-if="picture.noteid==323"
				class="codefun-self-start image_2"></image>
		</view> -->
		<image :src="pictures[0].pictureurl" mode="aspectFill"
		class=" codefun-self-start image_2"></image>
		<text class="codefun-self-start font_1 text_2" >{{notetitle}}</text>


		<view class="num">
			<image class="image_love" src="../../static/love.png" />

			<text>{{favorNum}}</text>
			<image class="image_love image_collect" src="../../static/store.png" />

			<text>{{starNum}}</text>

		</view>


	</view>
</template>

<script>
	export default {
		name: "starnoteview",
		props: {
			id: {
				type: Number,
				default: 0
			},
			notetitle: {
				type: String,
				default: "默认标题"
			}
		},
		data() {
			return {
				notes: [],
				//默认路径避免报错
				pictures: [{
					pictureurl: 'https://img0.baidu.com/it/u=1604010673,2427861166&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=889'
				}],
				favorNum: '',
				starNum: '',
			}
		},
		mounted() {
			this.getPicture(this.id);
			this.getFavorNum(this.id);
			this.getStarNum(this.id);
			console.log("加载社区笔记" + this.id)

		},
		methods: {

			naviToDetail() {
				uni.navigateTo({
					url: "../../pages/notedetail2/notedetail2?noteID="+this.id
				})
			},
			getFavorNum(noteid) {
				uni.request({
					url: 'http://localhost:8081/favor/favorNum/' + noteid,
					method: 'GET',
					header: {
						'content-type': 'application/json'
					},
					success: (res) => {
						if (res.statusCode === 200) {
							this.favorNum = res.data;;
						}
					},
					fail: (err) => {
						console.error(err);
					}
				});
			},
			getStarNum(noteid) {
				uni.request({
					url: 'http://localhost:8081/star/starList/starNum/' + noteid,
					method: 'GET',
					header: {
						'content-type': 'application/json'
					},
					success: (res) => {
						if (res.statusCode === 200) {
							this.starNum = res.data;
						}
					},
					fail: (err) => {
						console.error(err);
					}
				});
			},
			getPicture(noteid) {
				uni.request({
					url: 'http://localhost:8081/star/starList/picture/' + noteid,
					method: 'GET',
					header: {
						'content-type': 'application/json'
					},
					success: (res) => {
						if (res.statusCode === 200) {
							this.pictures = res.data;
						}
					},
					fail: (err) => {
						console.error(err);
					}
				});
			},
			
		}
	}
</script>

<style lang="scss">
	.starnoteview {
		padding: 34.88rpx 6.98rpx 13.95rpx 24.42rpx;
		height: 370rpx;
		background-color: #ffffff;
		border-radius: 13.95rpx;
		border: solid 8.72rpx #6073eb;
	}


	.image_2 {
		margin-left: 3.49rpx;
		width: 214.53rpx;
		height: 205.81rpx;
	}

	.image_love {
		width: 27.91rpx;
		height: 27.91rpx;
	}

	.image_collect {
		// margin-right: 76.74rpx;
	}

	.font_1 {
		font-size: 41.86rpx;
		font-family: AlimamaShuHeiTi;
		line-height: 33.14rpx;
		color: #1c167d;
	}

	.text_2 {
		// display: inline-block;
		// white-space: nowrap;
		// overflow: hidden;
		// text-overflow: ellipsis;
		// max-width: 10ch;
		margin-left: 3.49rpx;

	}
</style>